package com.example.premusic

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class CustomTextView(context: Context,attrs:AttributeSet?): AppCompatTextView(context, attrs) {
    init {
        //注册EventBus
        EventBus.getDefault().register(this)
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun changeColor(event:ChangeColorEvent){
        setTextColor(event.color)
    }


    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        //取消EventBus事件订阅
        EventBus.getDefault().unregister(this)
    }
}